fix: Hard link failure no longer copies+deletes originals (#209)#210
Merged
deucebucket merged 1 commit intodevelopfrom Apr 18, 2026
Merged
fix: Hard link failure no longer copies+deletes originals (#209)#210deucebucket merged 1 commit intodevelopfrom
deucebucket merged 1 commit intodevelopfrom
Conversation
When 'Use hard links' was enabled and the watch folder and library were on different filesystems, os.link() raised EXDEV and the code silently fell back to shutil.copy2() then deleted the originals. That broke torrent seeding, doubled disk use, and silently violated the user's explicit preference. - Add filesystem-compatibility pre-check in move_to_output_folder when use_hard_links is True. Returns a clear, actionable error if source and library are on different st_dev, without touching any source files. - Remove the EXDEV copy+delete fallback from both the single-file and directory-loop branches. Remaining OSErrors (permission, ENOSPC, etc.) propagate to the outer handler with source intact; the watch worker records the failure as watch_folder_error visible in the UI. - Bump APP_VERSION to 0.9.0-beta.147 and update README badge + CHANGELOG. Reported by @kyleviloria.
There was a problem hiding this comment.
🔍 Vibe Check Review
Context
Removes the silent shutil.copy2 + unlink fallback that move_to_output_folder used when os.link() hit EXDEV, and replaces it with an st_dev pre-check that fails fast with an actionable message before touching any source files.
Codebase Patterns I Verified
- Read
app.py:6393-6573— confirmed the oldused_copy_fallback/files_to_deletebookkeeping (lines 6495-6567 on develop) is what the diff strips out, and grep shows no references to those names anywhere else. - Confirmed the pre-check is placed after the
output.mkdir(parents=True, exist_ok=True)block (app.py:6411-6415) and aftersource.exists()validation (app.py:6408), so bothsource.stat()andoutput.stat()are safe to call. - Confirmed the atomic-move branch at
app.py:6480only runs whenuse_hard_linksis False, so the new guard doesn't interact with it. - Grepped for
os.link|EXDEV|Invalid cross-device— all hits are inside the removed block. No other location relies on the old fallback. OSErrorfromos.link(e.g.EACCES,ENOSPC) propagates to the outerexcept Exceptionhandler at the end of the function, which returns(False, None, str(e))— source files are left intact. Matches the CHANGELOG claim.
✅ Good
- Pre-check fixes the root cause (
EXDEVdestroying originals) rather than patching symptoms. Clear, actionable error message names the exact setting to toggle. - Guard is cheap (two
stat()calls) and only runs whenuse_hard_linksis on — zero cost for users not using hard links. FileNotFoundErrorfrom.stat()is correctly caught byexcept OSError(it's a subclass).- Version bumped consistently in
APP_VERSION, README badge, "Recent Changes" block, and CHANGELOG entry. - Empty-folder cleanup guard at line 6548 was correctly simplified — hardlink mode never needs cleanup now that copy fallback is gone, so
not use_hard_links and delete_emptyis the right condition.
🚨 Issues Found
No issues found.
📋 Scope Verification
| Issue | Problem | Addressed? | Notes |
|---|---|---|---|
| #209 | Hard-link failure silently copies + deletes originals | ✅ | Pre-check blocks cross-fs case; remaining OSErrors propagate without deletion. |
Scope Status: SCOPE_OK
📝 Documentation Check
- CHANGELOG.md: ✅ Updated (beta.147 entry explains root cause, fix, and reporter credit)
- README.md: ✅ Updated (version badge + "Recent Changes" callout flagging user-visible behavior change)
🎯 Verdict
APPROVE
This was referenced Apr 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #209
Summary
When
Use hard linkswas enabled and the watch folder and library lived on different filesystems,os.link()raisedEXDEVand LM silently fell back toshutil.copy2()followed by deleting each original file. That broke torrent seeding, doubled disk use, and silently violated the user's explicit "hard link" preference.Reported by @kyleviloria on v0.9.0-beta.134 (Docker). Log showed
Hard link failed, copy+delete:for every file in their downloaded book.Changes
app.pymove_to_output_folder— Added filesystem-compatibility pre-check. Whenuse_hard_links=Trueandsource.stat().st_dev != output.stat().st_dev, return a clear error immediately. No source files are touched. Error text is actionable: "Move your library to the same volume as the watch folder, or disable 'Use hard links' in Settings."app.pymove_to_output_folder— Removed the EXDEV copy+delete fallback from both the single-file branch (was ~L6614) and the directory-loop branch (was ~L6642). OtherOSErrors (permission,ENOSPC, existing target) propagate to the outer handler, which returns(False, None, error). The watch worker already records that aswatch_folder_errorwith the message visible in the UI.app.pymove_to_output_folder— Dropped now-unusedused_copy_fallback/files_to_delete/ post-loopf.unlink()block. Empty-folder cleanup is nowif not use_hard_links and delete_empty(hardlink mode leaves originals in place by design).APP_VERSIONbumped0.9.0-beta.146→0.9.0-beta.147.Behavior matrix
use_hard_links=True, same-fs: hardlink ✓use_hard_links=True, cross-fs: warn, copy+delete originals ✗use_hard_links=True, other OSError: raiseuse_hard_links=False:shutil.move(handles cross-fs internally)Test plan
move_to_output_folderwithuse_hard_links=Trueand source/output on different filesystems → returns(False, None, <error mentioning filesystems>), source files still present.(True, <dest>, None), hardlinks created, inode matches.watch_use_hard_links=True. Drop a book, run a scan. Expect the book to appear aswatch_folder_errorin the UI with the filesystem-mismatch message, and every source file still in the watch folder.use_hard_links=Falsepath unchanged.venv/bin/python test-env/test-naming-issues.py→ 290 passed, 0 failedruff check app.py --select=F821→ All checks passedNotes